package com.suning.sawp.service.impl.dao.task;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.suning.framework.dal.client.DalClient;
import com.suning.sawp.intf.dao.task.OrgRespmanDaoService;
import com.suning.sawp.po.task.OrgRespman;
import com.suning.sawp.service.util.BeanUtil;
@Service
public class OrgRespmanDaoServiceImpl implements OrgRespmanDaoService{

    @Resource
    DalClient dalClient;
    
    @Override
    public void insertOrgRespman(OrgRespman orgRespman) {
        dalClient.persist(orgRespman);
    }

    @Override
    public boolean updateOrgRespman(OrgRespman orgRespman, Integer Id) {
        Map<String,Object> paramMap = BeanUtil.describe(orgRespman);
        paramMap.put("condition_Id", Id);
        int update = dalClient.execute("ORG_RESPMAN.UPDATE_BY_ID", paramMap);
        return update > 0;
    }

    @Override
    public int queryOrgRespmanCountBycon(OrgRespman queryCon) {
        Map<String,Object> paramMap = BeanUtil.describe(queryCon);
        Map<String, Object> numMap = dalClient.queryForMap("ORG_RESPMAN.QUERY_COUNT_BY_CON", paramMap);
        return numMap != null ?  ((Number)numMap.get("NUM")).intValue() : 0;
    }

    @Override
    public List<OrgRespman> queryOrgRespmanByCon(OrgRespman queryCon, Integer pageNo,
            Integer pageSize) {
        Map<String,Object> paramMap = BeanUtil.describe(queryCon);
        if(pageNo != null && pageSize != null){
            paramMap.put("startIndex", (pageNo-1)*pageSize);
            paramMap.put("maxCount", pageSize);
        }
        return dalClient.queryForList("ORG_RESPMAN.QUERY_BY_CON", paramMap,OrgRespman.class);
    }

    /**
     * 查询大区干系人信息
     */
    @Override
    public OrgRespman getOrgRespman(String orgCode, String orgLevel) {
        Map<String,Object> paramMap = new HashMap<String,Object>();
        paramMap.put("orgCode", orgCode);
        paramMap.put("orgLevel", orgLevel);
        return dalClient.queryForObject("ORG_RESPMAN.GET_ORG_RESPMAN", paramMap, OrgRespman.class);
    }

}
